var lwobj = function()
{
	this.alive=[];
	this.x=[];
	this.y=[];
	this.len=[];
	this.spd=[];
	this.lwType=[];
	this.a=new Image();
	this.b=new Image();
	this.c=new Image();
	this.d=new Image();
	
	
	this.h=new Image();
	this.i=new Image();
	this.j=new Image();
	
	this.n=new Image();
	this.o=new Image();
	}
lwobj.prototype.num=30;
lwobj.prototype.init=function()
{
	for(var i = 0;i<this.num;i++)
	{
		 this.alive[i]=false;
		 this.x[i]=0;
		 this.y[i]=0;
		 this.spd[i]=Math.random()*0.03+0.005;
		 this.lwType[i]="";
		}
	this.a.src="SRC/红包4.png";
	this.b.src="SRC/红包1.png";
	this.c.src="SRC/红包3.png";
	this.d.src="SRC/红包2.png";

	this.h.src="SRC/红包5.png";
	this.i.src="SRC/红包6.png";
	this.j.src="SRC/红包7.png";

	this.n.src="SRC/红包8.png";
	this.o.src="SRC/红包9.png";
}
lwobj.prototype.draw=function()
{
	for(var i=0;i<this.num;i++)
	{ 
		if(this.alive[i])
		{
			if(this.lwType[i]=="1")
			{
				var pic = this.a;
				}
			if(this.lwType[i]=="2")
			{
				var pic = this.b;
				}
			if(this.lwType[i]=="3")
			{
				var pic = this.c;
				}
		    if(this.lwType[i]=="4")
			{
				var pic = this.d;
				}
			if(this.lwType[i]=="8")
			{
				var pic = this.h;
				}
			if(this.lwType[i]=="9")
			{
				var pic = this.i;
				}
			if(this.lwType[i]=="10")
			{
				var pic = this.j;
				}
			if(this.lwType[i]=="14")
			{
				var pic = this.n;
				}
            if(this.lwType[i]=="15")
			{
				var pic = this.o;
			}
		    if(this.len[i]<=70)
		   {
			this.len[i]+=this.spd[i]*deltaTime;
			}
			else
			{
				this.y[i]+=this.spd[i]*4*deltaTime;
			}
		   ctx2.drawImage(pic,this.x[i],this.y[i],this.len[i],this.len[i]);
		   if(this.y[i]>790)
		   {
			this.alive[i]=false;
			}
	    }
    }
	
}
lwobj.prototype.death=function(i)
{
	this.alive[i]=false;
	}
lwobj.prototype.born=function(i)
{

		this.x[i]=i*100+Math.random()*20;
		this.y[i]=i*1+Math.random()*20;;
        this.len[i]=0;
		this.alive[i]=true;
        var ran = Math.random();
		if(ran<0.17)
		{
			this.lwType[i]="1";
			}
		else if(ran>0.17&&ran<0.25)
		{
			this.lwType[i]="2";
			}
		else if(ran>0.25&&ran<0.35)
		{
			this.lwType[i]="3";
			}
		else if(ran>0.35&&ran<0.49)
		{
			this.lwType[i]="4";
			}
		else if(ran>0.49&&ran<0.51)
		{
			this.lwType[i]="8";
			}
		else if(ran>0.51&&ran<0.6)
		{
			this.lwType[i]="9";
			}
		else if(ran>0.6&&ran<0.7)
		{
			this.lwType[i]="10";
			}
		else if(ran>0.7&&ran<0.85)
		{
			this.lwType[i]="14";
			}
		else
		{
			this.lwType[i]="15";
			}
			
			
}
function lwMonitor()
{
	var num = 0;
	for(var i=0;i<lw.num;i++)
	{
		if(lw.alive[i])
		
		{
			num++;
		}
	}
	if(num<8)
	{
		sendlw();
		return;
		}
	}	
	
function sendlw()
{
	for (var i=0;i<lw.num;i++)
	{
		if(!lw.alive[i])
		{
			lw.born(i);
			return;
			}
		}
	}